package com.mer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mer.entity.TeacherExamine;
import com.mer.mapper.TeacherExamineMapper;
import com.mer.service.TeacherExamineService;
import com.mer.vo.CommonResult;
import com.mer.vo.TeacherExamineVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @program: IIPhase-project
 * @description:
 * @author: 张庆恒
 * @create: 2021-10-20 14:34
 **/
@Service
public class TeacherExamineServiceImpl extends ServiceImpl<TeacherExamineMapper, TeacherExamine> implements TeacherExamineService {
    @Resource
    private TeacherExamineMapper teacherExamineMapper;
    //查询未审核的讲师
    @Override
    public CommonResult queryNotApprovedTeacher(Integer page, Integer limit, TeacherExamineVo teacherExamineVo) {
        IPage<TeacherExamineVo> iPage = new Page<>(page, limit);
        QueryWrapper<TeacherExamineVo> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(teacherExamineVo.getName())) {
            wrapper.like("name", teacherExamineVo.getName());
        }
        if (StringUtils.isNotEmpty(teacherExamineVo.getMobile())) {
            wrapper.like("mobile", teacherExamineVo.getMobile());
        }
        if (StringUtils.isNotEmpty(teacherExamineVo.getStatus())) {
            wrapper.like("status", teacherExamineVo.getStatus());
        }
        wrapper.notIn("check_status", 1);
        IPage<TeacherExamineVo> selectPage = teacherExamineMapper.queryNotApprovedTeacher(iPage, wrapper);
        return new CommonResult(200, "查询成功", selectPage);
    }

    //审核新增的讲师
    @Override
    public CommonResult changeTeacherApproved(TeacherExamineVo teacherExamineVo) {
        System.out.println(teacherExamineVo);
        int i = 0;
        if (teacherExamineVo.getCheckStatus().equals("1")){
            Date date = new Date();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String time = format.format(date.getTime());
            teacherExamineVo.setCheckTime(time);
            System.out.println("1111111"+teacherExamineVo);
            i = teacherExamineMapper.changeTeacherApproved(teacherExamineVo);
            teacherExamineMapper.changeMember(teacherExamineVo.getMobile());
        }else {
            Date date = new Date();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String time = format.format(date.getTime());
            teacherExamineVo.setCheckTime(time);
            System.out.println("222222"+teacherExamineVo);
            i = teacherExamineMapper.changeTeacherApproved(teacherExamineVo);
        }
        if (i>0){
            return new CommonResult(200,"审核成功","yes");
        }else {
            return new CommonResult(500,"审核失败","no");
        }
    }


}
